import 'package:flutter/material.dart';

// 1. 定义自定义颜色类，它必须继承自 ThemeExtension
@immutable
class AppColorExtension extends ThemeExtension<AppColorExtension> {
  // 2. 将你 ColorUtils 中的所有颜色定义在这里，但使用 final Color?
  final Color? primaryColor;
  final Color? primaryAlphaColor;
  final Color? backgroundColor;
  final Color? lineColor;
  final Color? textDarkColor;
  final Color? textColors3;
  final Color? textColors6;
  final Color? textColors9;
  final Color? redColor;
  final Color? greenColor;
  final Color? whiteColor;

  const AppColorExtension({
    required this.primaryColor,
    required this.primaryAlphaColor,
    required this.backgroundColor,
    required this.lineColor,
    required this.textDarkColor,
    required this.textColors3,
    required this.textColors6,
    required this.textColors9,
    required this.redColor,
    required this.greenColor,
    required this.whiteColor,
  });

  // 3. 实现 copyWith 方法 (固定写法，用于主题切换)
  @override
  AppColorExtension copyWith({
    Color? primaryColor,
    Color? primaryAlphaColor,
    Color? backgroundColor,
    Color? lineColor,
    Color? textDarkColor,
    Color? textColors3,
    Color? textColors6,
    Color? textColors9,
    Color? redColor,
    Color? greenColor,
    Color? whiteColor,
  }) {
    return AppColorExtension(
      primaryColor: primaryColor ?? this.primaryColor,
      primaryAlphaColor: primaryAlphaColor ?? this.primaryAlphaColor,
      backgroundColor: backgroundColor ?? this.backgroundColor,
      lineColor: lineColor ?? this.lineColor,
      textDarkColor: textDarkColor ?? this.textDarkColor,
      textColors3: textColors3 ?? this.textColors3,
      textColors6: textColors6 ?? this.textColors6,
      textColors9: textColors9 ?? this.textColors9,
      redColor: redColor ?? this.redColor,
      greenColor: greenColor ?? this.greenColor,
      whiteColor: whiteColor ?? this.whiteColor,
    );
  }

  // 4. 实现 lerp 方法 (固定写法，用于主题切换时的平滑过渡动画)
  @override
  AppColorExtension lerp(ThemeExtension<AppColorExtension>? other, double t) {
    if (other is! AppColorExtension) {
      return this;
    }
    return AppColorExtension(
      primaryColor: Color.lerp(primaryColor, other.primaryColor, t),
      primaryAlphaColor: Color.lerp(primaryAlphaColor, other.primaryAlphaColor, t),
      backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t),
      lineColor: Color.lerp(lineColor, other.lineColor, t),
      textDarkColor: Color.lerp(textDarkColor, other.textDarkColor, t),
      textColors3: Color.lerp(textColors3, other.textColors3, t),
      textColors6: Color.lerp(textColors6, other.textColors6, t),
      textColors9: Color.lerp(textColors9, other.textColors9, t),
      redColor: Color.lerp(redColor, other.redColor, t),
      greenColor: Color.lerp(greenColor, other.greenColor, t),
      whiteColor: Color.lerp(whiteColor, other.whiteColor, t),
    );
  }
}
